package com.tanhua.server.controller;

import com.tanhua.model.domain.vo.NearUserVo;
import com.tanhua.model.domain.PageResult;
import com.tanhua.model.domain.dto.RecommendUserDto;
import com.tanhua.model.domain.TodayBest;
import com.tanhua.server.service.TanHuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author lk
 * @date 2022-03-25
 */

@RestController
@RequestMapping("/tanhua")
public class TanHuaController {
    @Autowired
    private TanHuaService tanhuaService;

    /**
     * 今日佳人
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询分页推荐好友列表
     */
    @GetMapping("/recommendation")  //recommendation 推荐
    public ResponseEntity responseEntity(RecommendUserDto dto){
        PageResult pageResult =tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 查看佳人详情
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
        TodayBest best = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(best);
    }

    /**
     * 查看陌生人问题
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String questions =  tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 回复陌生人问题
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestions(@RequestBody Map map){
        //前端传递的userId:是Integer类型的
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = map.get("reply").toString();
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 查询探花列表，查询时需要排除喜欢和不喜欢的用户
     */
    @GetMapping("/cards")
    public ResponseEntity queryCards(){
        List<TodayBest> list = tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }

    /**
     * 右划喜欢
     */
    @GetMapping("/{id}/love")
    public ResponseEntity likeUser(@PathVariable("id")Long likeUserId){
        tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 左划不喜欢
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity notLikeUser(@PathVariable("id")Long unLikeUserId){
        tanhuaService.unlikeUser(unLikeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜附近
     */
    @GetMapping("/search")
    public ResponseEntity<List<NearUserVo>> queryNearUser(String gender,@RequestParam(defaultValue = "2000")String distance){
        List<NearUserVo> list =tanhuaService.queryNearUser(gender,distance);
        return ResponseEntity.ok(list);
    }

}
